package generator;

import java.util.List;

import junit.framework.TestCase;

import org.dom4j.DocumentException;

/**
 * tests the compiler
 */
public class OpenOfficeDocTest extends TestCase {

    public static void main(String[] args) {
        junit.swingui.TestRunner.run(OpenOfficeDocTest.class);
    }

    private static String v1docText = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"
+ "<office:document-content xmlns:office=\"http://openoffice.org/2000/office\" xmlns:style=\"http://openoffice.org/2000/style\" xmlns:text=\"http://openoffice.org/2000/text\" xmlns:table=\"http://openoffice.org/2000/table\" xmlns:draw=\"http://openoffice.org/2000/drawing\" xmlns:fo=\"http://www.w3.org/1999/XSL/Format\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:number=\"http://openoffice.org/2000/datastyle\" xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns:chart=\"http://openoffice.org/2000/chart\" xmlns:dr3d=\"http://openoffice.org/2000/dr3d\" xmlns:math=\"http://www.w3.org/1998/Math/MathML\" xmlns:form=\"http://openoffice.org/2000/form\" xmlns:script=\"http://openoffice.org/2000/script\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" office:class=\"text\" office:version=\"1.0\">"
+ "<office:script />"
+ "<office:body>"
+ "<draw:image draw:style-name=\"fr6\" draw:name=\"Large Location Map (Layout)\" text:anchor-type=\"paragraph\" svg:x=\"5.05cm\" svg:y=\"0.349cm\" svg:width=\"9.999cm\" svg:height=\"8.481cm\" draw:z-index=\"1\" xlink:href=\"#Pictures/.*\\_13_.*\\.gif\" xlink:type=\"simple\" xlink:show=\"embed\" xlink:actuate=\"onLoad\">"
+ "<svg:desc>#.*\\_13_.*\\.gif#</svg:desc> "
+ "</draw:image>"
+ "</office:body>"
+ "</office:document-content>";

    // the tests...

    public final void testReplaceBR() {
    	OpenOfficeDoc oo = new OpenOfficeDoc();
    	oo.setContent("hello <br/> there");
    	assertEquals("hello <text:line-break xmlns:text=\"http://openoffice.org/2000/text\"/> there",oo.getContent());
    }

    public final void testReplaceMultipleBRs() {
    	OpenOfficeDoc oo = new OpenOfficeDoc();
    	oo.setContent("hello <br/> there<br/>");
    	assertEquals("hello <text:line-break xmlns:text=\"http://openoffice.org/2000/text\"/> there<text:line-break xmlns:text=\"http://openoffice.org/2000/text\"/>",oo.getContent());
    }

    public final void testGetImages() throws DocumentException {
    	OpenOfficeDoc doc = new OpenOfficeDoc();
    	doc.setContent(v1docText);
    	List images = doc.getImages();
    	assertEquals(1,images.size());
    }

}
